/*
 * =====================================================================================
 *
 *       Filename:  test_value_ptr.cxx
 *
 *    Description:  main for test ValuePtr
 *
 *        Version:  1.0
 *        Created:  02/15/2010 09:37:33 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ziliang), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#include "cl_value_ptr.hxx"
#include <iostream>
#include <vector>

using namespace std;
using namespace neo;

#if 0
class Y
{
public:
	Y(){ cout<< "Y()" <<endl; }		
	virtual ~Y(){ cout<<"~Y()"<<endl; }
};


class X
{
public:
	X( Y* y ) : y_( y ){} 

	~X() {}

	X( const X& other ) : y_( other.y_ ) {}

	X& operator=( const X& other )
	{
		X temp( other );
		swap( temp );
		return *this;
	}

private:
	void swap( X& other ) { y_.swap( other.y_ ); }

private:
	ValuePtr<Y> y_;
};
#endif

class A{
public:
	A(){ cout << "A()" << endl; }
	void print( void ) const
	{
		cout<< "A::print" << endl;
	}
};

class B{
public:
	B( A* a): _a(a) { cout << "B()" << endl; }
	void print( void ) const
	{
		cout << "B::print" << endl;
		_a->print();
	}
private:
	ValuePtr<A> _a;
};

class C{
public:
	C(){ cout << "C()" << endl; }
	void addB(  const B& b )
	{
		_vb.push_back( b );
	}
	
	void print( void )const
	{
		vector<B>::const_iterator first ( _vb.begin() );
		vector<B>::const_iterator last ( _vb.end() ) ;

		for( ; first != last ; ++first )
		{
			first->print();
		}
	}

private:
	vector<B> _vb;
};

int main( int argc, char** argv )
{
#if 0
	Y* y = new Y;
	X x(y);
	X x1(x);
	Y* y2 = new Y;
	X x2(y2);
	x2 = x1;
#endif
	C c;
	for( int i=0; i < 10; i++ )
	{
		A* a = new A;
		B b( a );
		c.addB( b );
	}

	c.print();

	return 0;
}

